
#include "Square.h"

Square::Square()  {
   thePiece = NULL;
}

Square::~Square() {
   delete thePiece;
}

Piece * Square::GetPiece() {
   return thePiece;
}

Piece * Square::AddPiece(std::string type, bool white) {
   if (thePiece != NULL)
      return thePiece;

   if (type.compare("Pawn")==0) {
      thePiece = new Pawn(white);
   }
   else if (type.compare("Rook")==0) {
      thePiece = new Rook(white);
   }
   else if (type.compare("Bishop")==0) {
      thePiece = new Bishop(white);
   }
   else if (type.compare("Knight")==0) {
      thePiece = new Knight(white);
   }
   else if (type.compare("Queen")==0) {
      thePiece = new Queen(white);
   }
   else if (type.compare("King")==0) {
      thePiece = new King(white);
   }
   else {
      thePiece = NULL;
   }

   return thePiece;
}

bool Square::SetPiece(Piece * nxt) {
   thePiece = nxt;

   return true;
}

Piece * Square::RemovePiece() {
   Piece * toRet = thePiece;

   thePiece = NULL;

   return toRet;
}